package com.jtny.nytb.weather.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 天气信息类型枚举
 */
@AllArgsConstructor
@Getter
public enum WeatherInfoTypeEnum {

    REAL_TIME_WEATHER("实时天气", 0),
    HALF_MONTH_WEATHER("半个月天气", 1),
    WEATHER_FORECAST_CURRENT_DAY("当天天气预测", 2),
    HALF_MONTH_WEATHER_FORECAST("半个月天气预测", 3),
    WEATHER_WARNING("天气预警", 4),
    METEOROLOGICAL_CONSULTATION("气象咨询", 5),
    ;

    /**
     * 枚举描述
     */
    private String desc;

    /**
     * 枚举值
     */
    private Integer value;

    /**
     * 通过枚举值获取枚举对象
     * @param value 枚举值
     * @return 返回枚举对象
     */
    public static WeatherInfoTypeEnum getEnum(Integer value) {
        if (value == null) {
            return null;
        }

        for (WeatherInfoTypeEnum enumTemp : WeatherInfoTypeEnum.values()) {
            if (enumTemp.getValue().equals(value)) {
                return enumTemp;
            }
        }

        return null;
    }

    /**
     * 获取值列表
     *
     * @return
     */
    public static List<Integer> getValues() {
        return Arrays.stream(values()).map(item -> item.value).collect(Collectors.toList());
    }
}
